package com.mind.battle;

import com.mind.common.MessageCode;
import com.mind.core.handler.MessageHandler;
import com.mind.core.net.msg.Message;
import com.mind.login.model.Player;
import com.mind.login.model.PlayerBattleProperty;

public class BattleHandler implements MessageHandler<Message>{

	@Override
	public void execute(Message message) {
		Player player=(Player) message.sender();
		switch(message.getMessageType()){
		case MessageCode.EnterBattleRoomMessage_CODE:
			EnterBattleRoomMessage msg=(EnterBattleRoomMessage)message;
			if(player.battleProperty==null){
				player.battleProperty=new PlayerBattleProperty(
						msg.getX(), msg.getY(), msg.getXSpeed(),
						msg.getYSpeed(), msg.getXDriction(), msg.getYDriction());
			}else{
				player.battleProperty.setX(msg.getX());
				player.battleProperty.setY(msg.getY());
				player.battleProperty.setxSpeed(msg.getXSpeed());
				player.battleProperty.setySpeed(msg.getYSpeed());
				player.battleProperty.setxDriction(msg.getXDriction());
				player.battleProperty.setyDriction(msg.getYDriction());
			}
			BattleManager.getInstance().enterRoom(player, msg.getRoomId());
			break;
		}
		
	}

	@Override
	public short[] getTypes() {
		return new short[]{
				MessageCode.EnterBattleRoomMessage_CODE,
				1001};
	}

}
